/**
 * Created with IntelliJ IDEA.
 * User: Hkkkk Guo
 * Date: 2023/2/8
 * Time: 16:26
 * Description:
 */
package com.hangkai.reggie.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;


/**
 * 通用返回结果 服务端的数据都会封装成此对象
 */
@Data
public class Result<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;
    private Map<String, Object> map = new HashMap<>();

    public static <T> Result<T> success(T object){
        Result<T> res = new Result<T>();
        res.data = object;
        res.code = Code.SUCCESS;
        return res;
    }

    public static <T> Result<T> error(String msg){
        Result<T> res = new Result<>();
        res.msg = msg;
        res.code = Code.FAIL;
        return res;
    }
    public Result<T> add (String key, Object value){
        this.map.put(key, value);
        return this;
    }
}
